package ControllerLayer;

import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 *
 * @author Gruppe 2
 */
public class ProductController {

    private static ProductController instance;
    private IFDBProduct dBProduct = new DBProduct();

    private ProductController()
    {
    }

    public static synchronized ProductController getInstance()
    {
        if (instance == null)
        {
            instance = new ProductController();
        }
        return instance;
    }
    
    //get all Product
    //public ArrayList getAllProduct(boolean retriveAssociation);

    //get one Product having the ID
    public Product findProduct(int ID, boolean retriveAssociation)
    {
        Product pro = null;
        pro = dBProduct.findProduct(ID, retriveAssociation);
        return pro;
    }

    //find one Product having the Product name
    public Product searchProductOnName(String name, boolean retriveAssociation)
    {
        Product pro = null;
        pro = dBProduct.searchProductOnName(name, retriveAssociation);
        return pro;
    }

    //insert new Product
    public boolean createProduct(String productID, String name, double purchasePrice, double salesPrice, double rentPrice, String countryOfOrigin, int minStock, Supplier supplier)
    {
        Product product = new Product();
        product.setProductID(productID);
        product.setName(name);
        product.setPurchasePrice(purchasePrice);
        product.setSalesPrice(salesPrice);
        product.setRentPrice(rentPrice);
        product.setCountryOfOrigin(countryOfOrigin);
        product.setMinStock(minStock);
        product.setSupplier(supplier);

        boolean affected = false;
        if (dBProduct.insert(product) > 0)
        {
            affected = true;
        }
        return affected;
    }

    //update Product
    //public int update(Product prod);


    //delete Product
    //public int delete(Product prod);
}
